// pages/custom/index.js

const app = getApp()
const { getPerfumeOrderWaitList } = require('../../services/api/custom.js')
const { getAdvImg } = require('../../services/api/common.js')
Page({
  data: {
    OrderWai:false,
    offlineCustom:false,
    imgUrl:'/assets/tmps/custom-top.jpg',
    envVersion:wx.getAccountInfoSync().miniProgram.envVersion
  },
  onLoad(){
    this.getAdvImg()
  },
  onShow() {
    app.initPageLang(this)
    this.loadData()
    this.isOfflineCustom()
  },
  isOfflineCustom() {
    this.setData({
      offlineCustom: app.data.offlineCustom
    })
    app.getUnmakeList(() => {
      this.setData({
        offlineCustom: app.data.offlineCustom
      })
    })
  },
  test(){
    wx.navigateTo({
      url: '/subpackages/custom/customTest/index',
    })
  },
  loadData(){
    getPerfumeOrderWaitList().then(res=>{
      if(res.code==0&&res.info.length>0){
        this.setData({
          OrderWai:true
        })
      }
    })
  },
  toLink() {
    app.toTinymceView(app.data.playImgUrlData)
  },
  getAdvImg() {
    getAdvImg(3).then(res => {
      if (res.code === 0) {
        try {
          this.setData({
            imgUrl:res.info.advertInfoList[0].imgUrl
          })
          app.data.playImgUrlData = {
            imgUrl:res.info.advertInfoList[0].imgUrl,
            includeSubsets:res.info.advertInfoList[0].includeSubsets,
            advertisingPositionName: res.info.advertInfoList[0].advertisingPositionName,
            content: res.info.advertInfoList[0].content,
          }
        } catch (error) {
          
        }
      }
    })
  },

  toCustom(){
    wx.navigateTo({
      url:'/subpackages/custom/doing/index?type=offlineCustom',
    })
  },
})